// Name:          Modal
//
// Description:   Define style for Modal Plugin
//
// =============================================================================
// Modal Variables
// =============================================================================
@modal-bg-color: #f8f8f8;
@modal-btn-color : @global-primary;
@modal-btn-bg: @modal-bg-color;
@modal-btn-active-bg: #d4d4d4;
@modal-duration: 300ms;
@modal-border-color: #dedede;
@modal-border-radius: @global-radius;
@modal-actions-duration: @modal-duration;
@modal-actions-btn-bg: rgba(243, 243, 243, 0.95);
@modal-actions-active-btn-bg: #dcdcdc;
@modal-popup-duration: @modal-duration;
@modal-lg: 810px;
@modal-md: 540px;
@modal-sm: 270px;

/*
TODO:
  1. 动画应该放在 dialog 上，不再是整个 modal，涉及 JS 逻辑，需要统筹修改
  2. modal 滚动条处理，是否需要添加一个滚动条宽度的水平 padding？
*/


/* ==========================================================================
   Component: Modal Plugin
 ============================================================================ */

.@{ns}modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    // z-index: @z-index-modal;
    opacity: 0;
    outline: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    // @see https://github.com/amazeui/amazeui/issues/712
    // transform: translate3d(0, 0, 0) scale(1.185);
    transform: scale(1.185);
    transition-property: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
    &:focus {
        outline: 0;
    }
    &.@{ns}modal-active {
        opacity: 1;
        transition-duration: @modal-duration;
        // transform: translate3d(0, 0, 0) scale(1);
        transform: scale(1);
        overflow-x: hidden;
        overflow-y: auto;
    }
    &.@{ns}modal-out {
        opacity: 0;
        z-index: @z-index-modal - 1;
        transition-duration: @modal-duration;
        // transform: translate3d(0, 0, 0) scale(0.815);
        transform: scale(0.815);
    }
    // vertical centering hack
    &:before {
        // @see http://www.fileformat.info/info/unicode/char/200b/index.htm
        content: "\200B";
        display: inline-block;
        height: 100%;
        vertical-align: middle;
    }
    .hook-modal;
}

.@{ns}modal-dialog {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    margin-left: auto;
    margin-right: auto;
    width: @modal-sm;
    max-width: 100%;
    border-radius: @modal-border-radius;
    background: @modal-bg-color;
    @media @medium-up {
        width: @modal-md;
    }
    /*@media @large-up {
    width: @modal-lg;
    margin-left: -@modal-lg/2;
  }*/
    .hook-modal-dialog;
}

.@{ns}modal-hd {
    padding: 15px 10px 0px 10px;
    font-size: 1.6rem;
    .@{ns}close {
        position: absolute;
        top: 4px;
        right: 4px;
    }
    .hook-modal-hd;
}

.@{ns}modal-bd {
    padding: 15px;
    border-radius: 2px 2px 0 0;
    border-bottom: 1px solid @modal-border-color;
    // References https://github.com/allmobilize/amazeui/issues/464
    // overflow: hidden;
    +.@{ns}modal-bd {
        margin-top: 5px;
    }
    .hook-modal-hd;
}

// fix by my
.@{ns}modal-alert, .@{ns}modal-confirm, .@{ns}modal-prompt {
    .@{ns}modal-bd {
        text-align: center;
    }
}
.@{ns}modal-toast {
    .@{ns}modal-dialog {
        width: auto;
        background-color: rgba(0, 0, 0, 0.4);
        color: #bbb;

        .@{ns}modal-bd {
            padding-left: 20px;
            padding-right: 20px;
            border-bottom: 0px;

            .@{ns}modal-toast-message {
                margin-left: 4px;
            }
        }
    }
}

// Prompt input
.@{ns}modal-prompt-input {
    display: block;
    margin: 5px auto 0 auto;
    border-radius: @modal-border-radius;
    padding: 5px;
    line-height: 1.8rem;
    width: 80%;
    border: 1px solid @modal-border-color;
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    appearance: none;
    &:focus {
        outline: none;
        border-color: darken(@modal-border-color, 3%);
    }
    .hook-modal-prompt-input;
}

.@{ns}modal-footer {
    height: 44px;
    overflow: hidden;
    display: table;
    width: 100%;
    border-collapse: collapse;
    .hook-modal-footer;

    >.@{ns}btn:not(.@{ns}modal-btn) {
        float: right;
        margin-right: 8px;
        margin-top: 6px;
        margin-bottom: 6px;
    }
}

.@{ns}modal-btn {
    display: table-cell!important;
    padding: 0 5px;
    height: 44px;
    box-sizing: border-box !important;
    font-size: 1.6rem;
    line-height: 44px;
    text-align: center;
    color: @global-primary;
    .text-overflow(block);
    cursor: pointer;
    border-right: 1px solid @modal-border-color;
    &:first-child {
        border-radius: 0 0 0 @modal-border-radius;
    }
    &:last-child {
        border-right: none;
        border-radius: 0 0 @modal-border-radius 0;
    }
    &:first-child:last-child {
        border-radius: 0 0 @modal-border-radius @modal-border-radius;
    }
    &.@{ns}modal-btn-bold {
        font-weight: 500;
    }
    &:active {
        background: @modal-btn-active-bg;
    }
    &+.@{ns}modal-btn {
        border-left: 1px solid @modal-border-color;
    }
    .hook-modal-btn;
}

// without buttons
// -----------------------------------------------------------------------------
.@{ns}modal-no-btn {
    .@{ns}modal-dialog {
        border-radius: @global-radius;
        border-bottom: none;
    }
    .@{ns}modal-bd {
        border-bottom: none;
    }
    .@{ns}modal-footer {
        display: none;
    }
    .hook-modal-no-btn;
}

// Loading
// =============================================================================
.@{ns}modal-loading {
    .@{ns}modal-bd {
        border-bottom: none;
    }
    .@{ns}icon-spin {
        display: inline-block;
        font-size: 2.4rem;
    }
    .@{ns}modal-footer {
        display: none;
    }
    .hook-modal-loading;
}

// Modal - Action
// ========================================================================
.@{ns}modal-actions {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: @z-index-modal;
    width: 100%;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    text-align: center;
    border-radius: @modal-border-radius;
    transform: translateY(100%);
    transition: transform @modal-actions-duration;
    &.@{ns}modal-active {
        transform: translateY(0);
    }
    &.@{ns}modal-out {
        z-index: @z-index-modal - 1;
        transform: translateY(100%);
    }
    .hook-modal-actions;
}

.@{ns}modal-actions-group {
    margin: 10px;
    .@{ns}list {
        margin: 0;
        border-radius: @modal-border-radius;
        &>li {
            margin-bottom: 0;
            border-bottom: none;
            .text-overflow();
            box-shadow: inset 0 1px 0 rgba(0, 0, 0, 0.015);
            &>a {
                padding: 1rem;
                .text-overflow();
            }
            &:first-child {
                border-top: none;
                .border-top-radius(@modal-border-radius);
            }
            &:last-child {
                border-bottom: none;
                .border-bottom-radius(@modal-border-radius);
            }
        }
    }
}

.@{ns}modal-actions-header {
    padding: 1rem;
    color: @gray-light;
    font-size: 1.4rem;
}

.@{ns}modal-actions-danger {
    color: @global-danger;
    a {
        color: inherit;
    }
}

// Modal Popup
// ========================================================================
.@{ns}popup {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: @z-index-modal;
    background: #fff;
    overflow: hidden;
    transition-property: transform;
    transform: translateY(100%);
    &.@{ns}modal-active, &.@{ns}modal-out {
        transition-duration: @modal-popup-duration;
    }
    &.@{ns}modal-active {
        transform: translateY(0);
    }
    &.@{ns}modal-out {
        transform: translateY(100%);
    }
    // iPad Modal
    @media all and (min-width: 630px) and (min-height: 630px) {
        width: 630px;
        height: 630px;
        left: 50%;
        top: 50%;
        margin-left: -315px;
        margin-top: -315px;
        transform: translateY(1024px);
        &.@{ns}modal-active {
            transform: translateY(0);
        }
        &.@{ns}modal-out {
            transform: translateY(1024px);
        }
    }
    .hook-popup;
}

.@{ns}popup-inner {
    padding-top: 44px;
    height: 100%;
    .scrollable();
    .hook-popup-inner;
}

.@{ns}popup-hd {
    position: absolute;
    top: 0;
    z-index: @global-z-index;
    width: 100%;
    height: 43px;
    border-bottom: 1px solid @modal-border-color;
    background-color: #fff;
    .@{ns}popup-title {
        font-size: 1.8rem;
        line-height: 43px;
        text-align: center;
        margin: 0 30px;
        color: @gray-dark;
        .text-overflow();
    }
    .@{ns}close {
        position: absolute;
        right: 10px;
        top: 8px;
        cursor: pointer;
        transition: all 0.3s;
        color: @gray-light;
        &:hover {
            transform: rotate(360deg);
            color: @gray;
        }
    }
    .hook-popup-hd;
}

.@{ns}popup-bd {
    padding: 15px;
    background: #f8f8f8;
    color: @gray;
    .hook-popup-bd;
}

.@{ns}dimmer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .6);
    z-index: @z-index-dimmer;
    opacity: 0;
    // transition: opacity .15s;
    &.@{ns}active {
        opacity: 1;
    }
}

// Hooks
// =============================================================================
.hook-modal() {}

.hook-modal-hd() {}

.hook-modal-bd() {}

.hook-modal-footer() {}

.hook-modal-dialog() {}

.hook-modal-prompt-input() {}

.hook-modal-btn() {}

.hook-modal-no-btn() {}

.hook-modal-loading() {}

.hook-modal-actions() {}

.hook-popup() {}

.hook-popup-inner() {}

.hook-popup-hd() {}

.hook-popup-bd() {}

@media @small-only {
    .@{ns}modal-hd {
        text-align: center;
        padding: 15px 10px 5px 10px;
        font-size: 1.6rem;
    }
}
